//
//  smContratDetailController.m
//  shimaoHouse
//
//  Created by haifan wu on 12-6-29.
//  Copyright (c) 2012年 yst. All rights reserved.
//

#import "smContratDetailController.h"
#import "smloginController.h"
#import "smPaymentController.h"
#import "smMboSmTbContract.h"


@interface smContratDetailController ()<UITableViewDelegate,UITextFieldDelegate>
@property (nonatomic, strong) UILabel* contratNumberLabel;
@property (nonatomic, strong) UITextField* contratNumberFiled;
@property (nonatomic, strong) UILabel* contratFirstrLabel;
@property (nonatomic, strong) UITextField* contratFirsFiled;
@property (nonatomic, strong) UILabel* contratFirsPhonetrLabel;
@property (nonatomic, strong) UITextField* contratFirsPhoneFiled;
@property (nonatomic, strong) UILabel* contratSecondtrLabel;
@property (nonatomic, strong) UITextField* contratSecondFiled;
@property (nonatomic, strong) UILabel* contratSecondPhonetrLabel;
@property (nonatomic, strong) UITextField* contratSecondPhoneFiled;
@property (nonatomic, strong) UILabel* contratIdentityLabel;
@property (nonatomic, strong) UITextField* contratIdentityFiled;
@property (nonatomic, strong) UILabel* contratAdressLabel;
@property (nonatomic, strong) UITextField* contratAdressFiled;
@property (nonatomic, strong) UILabel* contratPriceLabel;
@property (nonatomic, strong) UITextField* contratPriceFiled;
@property (nonatomic, strong) UILabel* contratTotalLabel;
@property (nonatomic, strong) UITextField* contratTotalFiled;
@property (nonatomic, strong) UILabel* contratPayLabel;
@property (nonatomic, strong) UISwitch* leftSwitch;
@property (nonatomic, strong) UISwitch* rightSwitch;
@property (nonatomic, strong) smMboSmTbContract* contract;





@end

@implementation smContratDetailController
@synthesize contratNumberLabel=_contratNumberLabel;
@synthesize contratNumberFiled=_contratNumberFiled;
@synthesize contratFirstrLabel=_contratFirstrLabel;
@synthesize contratFirsFiled=_contratFirsFiled;
@synthesize contratFirsPhonetrLabel=_contratFirsPhonetrLabel;
@synthesize contratFirsPhoneFiled=_contratFirsPhoneFiled;
@synthesize contratSecondtrLabel=_contratSecondtrLabel;
@synthesize contratSecondFiled=_contratSecondFiled;
@synthesize contratSecondPhonetrLabel=_contratSecondPhonetrLabel;
@synthesize contratSecondPhoneFiled=_contratSecondPhoneFiled;
@synthesize contratIdentityLabel=_contratIdentityLabel;
@synthesize contratIdentityFiled=_contratIdentityFiled;
@synthesize contratAdressLabel=_contratAdressLabel;
@synthesize contratAdressFiled=_contratAdressFiled;
@synthesize contratPriceLabel=_contratPriceLabel;
@synthesize contratPriceFiled=_contratPriceFiled;
@synthesize contratTotalLabel=_contratTotalLabel;
@synthesize contratTotalFiled=_contratTotalFiled;
@synthesize contratPayLabel=_contratPayLabel;
@synthesize leftSwitch = _leftSwitch;
@synthesize rightSwitch = _rightSwitch;
@synthesize contract = _contract;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    //后退
    UIButton* backButton=[UIButton buttonWithType:UIButtonTypeCustom];
    backButton.frame=CGRectMake(5, 5, 118, 52);
    [backButton setImage:[UIImage imageNamed:@"back_button_up.png"] forState:UIControlStateNormal];
    [backButton setImage:[UIImage imageNamed:@"back_button_down.png"] forState:UIControlStateHighlighted];
    backButton.backgroundColor=[UIColor clearColor];
    [backButton addTarget:self action:@selector(backClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:backButton];

    
    [self.navigationController.navigationBar setHidden:YES];
    [self.view setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"contrat_detail_backgroud.png"]]];
//    
//    
//      UILabel* programnameLabel = [[UILabel alloc] initWithFrame:CGRectMake(74, 250, 100, 30)];
//      programnameLabel.font = [UIFont systemFontOfSize:29];
//      programnameLabel.textColor=[UIColor colorWithRed:124/255.0 green:124/255.0 blue:124/255.0 alpha:1.0];
//      [programnameLabel setText:@"   合同编号：A000-100"];
//      [self.view addSubview:programnameLabel];
    
      self.contratNumberLabel = [[UILabel alloc] initWithFrame:CGRectMake(74, 220, 200, 50)];
      self.contratNumberLabel.font = [UIFont systemFontOfSize:22];
      self.contratNumberLabel.textColor=[UIColor colorWithRed:124/255.0 green:124/255.0 blue:124/255.0 alpha:1.0];
     [self.contratNumberLabel setText:@"合同编号"];    
    [self.contratNumberLabel setBackgroundColor:[UIColor clearColor]];    
     [self.view  addSubview:self.contratNumberLabel];
    
    NSNumberFormatter* numberFormatter = [[NSNumberFormatter alloc] init];
//	// Do any additional setup after loading the view.
//    
//    
      self.contratNumberFiled = [[UITextField alloc] initWithFrame:CGRectMake(200, 220, 500, 50)];
      [self.contratNumberFiled setBackgroundColor:[UIColor colorWithRed:215/255.0 green:226/255.0 blue:243/255.0 alpha:1.0]];
      [self.contratNumberFiled setText:[numberFormatter stringFromNumber:[self.contract id_]]];
      [self.contratNumberFiled setDelegate:self];
      self.contratNumberFiled.borderStyle=UITextBorderStyleRoundedRect;
      [self.view  addSubview:self.contratNumberFiled];
//    
//    /*********************甲方****************************/
      self.contratFirstrLabel = [[UILabel alloc] initWithFrame:CGRectMake(74, 300, 100, 50)];
      self.contratFirstrLabel.font = [UIFont systemFontOfSize:22];
      self.contratFirstrLabel.textColor=[UIColor colorWithRed:124/255.0 green:124/255.0 blue:124/255.0 alpha:1.0];
      [self.contratFirstrLabel setBackgroundColor:[UIColor clearColor]];    
      [self.contratFirstrLabel setText:@"甲  方"];    

      [self.view  addSubview:self.contratFirstrLabel];
//	// Do any additional setup after loading the view.
      self.contratFirsFiled = [[UITextField alloc] initWithFrame:CGRectMake(200, 300, 150, 50)];
     [self.contratFirsFiled setBackgroundColor:[UIColor colorWithRed:215/255.0 green:226/255.0 blue:243/255.0 alpha:1.0]];
     [self.contratFirsFiled setDelegate:self];
     self.contratFirsFiled.borderStyle=UITextBorderStyleRoundedRect;
     [self.contratFirsFiled setText:[self.contract firstParty]];
     [self.view  addSubview:self.contratFirsFiled];
    
     self.contratFirsPhonetrLabel = [[UILabel alloc] initWithFrame:CGRectMake(400, 300, 100, 50)];
    [self.contratFirsPhonetrLabel setText:@"甲方电话"];
    self.contratFirsPhonetrLabel.font = [UIFont systemFontOfSize:22];
    self.contratFirsPhonetrLabel.textColor=[UIColor colorWithRed:124/255.0 green:124/255.0 blue:124/255.0 alpha:1.0];
    [self.contratFirsPhonetrLabel setBackgroundColor:[UIColor clearColor]];
    //加载lable
    [self.view  addSubview:self.contratFirsPhonetrLabel];
	// Do any additional setup after loading the view.
    
    
    self.contratFirsPhoneFiled = [[UITextField alloc] initWithFrame:CGRectMake(500, 300, 200, 50)];
    [self.contratFirsPhoneFiled setText:[self.contract firstTelephone]];
    [self.contratFirsPhoneFiled setDelegate:self];
    [self.contratFirsPhoneFiled setBackgroundColor:[UIColor colorWithRed:215/255.0 green:226/255.0 blue:243/255.0 alpha:1.0]];
    self.contratFirsPhoneFiled.borderStyle=UITextBorderStyleRoundedRect;
    
    [self.view  addSubview:self.contratFirsPhoneFiled];
    /*********************甲方****************************/
    
    
    /*********************乙方****************************/
    self.contratSecondtrLabel = [[UILabel alloc] initWithFrame:CGRectMake(74, 380, 100, 50)];
    [self.contratSecondtrLabel setText:@"乙  方"]; 
    self.contratSecondtrLabel.font = [UIFont systemFontOfSize:22];
    self.contratSecondtrLabel.textColor=[UIColor colorWithRed:124/255.0 green:124/255.0 blue:124/255.0 alpha:1.0];
    [self.contratSecondtrLabel setBackgroundColor:[UIColor clearColor]];
    //加载lable
    [self.view  addSubview:self.contratSecondtrLabel];
	// Do any additional setup after loading the view.
    
    
    self.contratSecondFiled = [[UITextField alloc] initWithFrame:CGRectMake(200, 380, 150, 50)];
    [self.contratSecondFiled setText:[self.contract secondParty]];
    [self.contratSecondFiled setDelegate:self];
    [self.contratSecondFiled setBackgroundColor:[UIColor colorWithRed:215/255.0 green:226/255.0 blue:243/255.0 alpha:1.0]];
    self.contratSecondFiled.borderStyle=UITextBorderStyleRoundedRect;
    [self.view  addSubview:self.contratSecondFiled];
    
    
    self.contratSecondPhonetrLabel = [[UILabel alloc] initWithFrame:CGRectMake(400, 380, 100, 50)];
    [self.contratSecondPhonetrLabel setText:@"乙方电话"];    
    self.contratSecondPhonetrLabel.font = [UIFont systemFontOfSize:22];
    self.contratSecondPhonetrLabel.textColor=[UIColor colorWithRed:124/255.0 green:124/255.0 blue:124/255.0 alpha:1.0];
    [self.contratSecondPhonetrLabel setBackgroundColor:[UIColor clearColor]];
    //加载lable
    [self.view  addSubview:self.contratSecondPhonetrLabel];
	// Do any additional setup after loading the view.
    
    
    self.contratSecondPhoneFiled = [[UITextField alloc] initWithFrame:CGRectMake(500, 380, 200, 50)];
    [self.contratSecondPhoneFiled setText:[self.contract secondTelephone]];
    [self.contratSecondPhoneFiled setDelegate:self];
    [self.contratSecondPhoneFiled setBackgroundColor:[UIColor colorWithRed:215/255.0 green:226/255.0 blue:243/255.0 alpha:1.0]];
    self.contratSecondPhoneFiled.borderStyle=UITextBorderStyleRoundedRect;
    
    [self.view  addSubview:self.contratSecondPhoneFiled];
    /*********************乙方****************************/
    
    
    self.contratIdentityLabel = [[UILabel alloc] initWithFrame:CGRectMake(74, 460, 100, 50)];
    [self.contratIdentityLabel setText:@"身份证"];    
    self.contratIdentityLabel.font = [UIFont systemFontOfSize:22];
    self.contratIdentityLabel.textColor=[UIColor colorWithRed:124/255.0 green:124/255.0 blue:124/255.0 alpha:1.0];
    [self.contratIdentityLabel setBackgroundColor:[UIColor clearColor]];
    //加载lable
    [self.view  addSubview:self.contratIdentityLabel];
	// Do any additional setup after loading the view.
    
    
    self.contratIdentityFiled = [[UITextField alloc] initWithFrame:CGRectMake(200, 460, 500, 50)];
    [self.contratIdentityFiled setText:[self.contract indetityCard]];
    [self.contratIdentityFiled setDelegate:self];
    [self.contratIdentityFiled setBackgroundColor:[UIColor colorWithRed:215/255.0 green:226/255.0 blue:243/255.0 alpha:1.0]];
    self.contratIdentityFiled.borderStyle=UITextBorderStyleRoundedRect;
    [self.view  addSubview:self.contratIdentityFiled];
    
    
    self.contratAdressLabel = [[UILabel alloc] initWithFrame:CGRectMake(74, 540, 100, 50)];
    [self.contratAdressLabel setText:@"地  址"];    
    self.contratAdressLabel.font = [UIFont systemFontOfSize:22];
    self.contratAdressLabel.textColor=[UIColor colorWithRed:124/255.0 green:124/255.0 blue:124/255.0 alpha:1.0];
    [self.contratAdressLabel setBackgroundColor:[UIColor clearColor]];
    //加载lable
    [self.view  addSubview:self.contratAdressLabel];
	// Do any additional setup after loading the view.
    
    
    self.contratAdressFiled = [[UITextField alloc] initWithFrame:CGRectMake(200, 540, 500, 50)];
    [self.contratAdressFiled setText:[self.contract address]];
    [self.contratAdressFiled setDelegate:self];
    [self.contratAdressFiled setBackgroundColor:[UIColor colorWithRed:215/255.0 green:226/255.0 blue:243/255.0 alpha:1.0]];
    self.contratAdressFiled.borderStyle=UITextBorderStyleRoundedRect;
    [self.view  addSubview:self.contratAdressFiled];
    
    /*******价格 start********/
    self.contratPriceLabel = [[UILabel alloc] initWithFrame:CGRectMake(74, 620, 100, 50)];
    [self.contratPriceLabel setText:@"单 价"];    
    self.contratPriceLabel.font = [UIFont systemFontOfSize:22];
    self.contratPriceLabel.textColor=[UIColor colorWithRed:124/255.0 green:124/255.0 blue:124/255.0 alpha:1.0];
    [self.contratPriceLabel setBackgroundColor:[UIColor clearColor]];
    //加载lable
    [self.view  addSubview:self.contratPriceLabel];
	// Do any additional setup after loading the view.
    
    
    self.contratPriceFiled = [[UITextField alloc] initWithFrame:CGRectMake(200, 620, 150, 50)];
    [self.contratPriceFiled setText:[numberFormatter stringFromNumber:[self.contract unitPrice]]];
    [self.contratPriceFiled setDelegate:self];
    [self.contratPriceFiled setBackgroundColor:[UIColor colorWithRed:215/255.0 green:226/255.0 blue:243/255.0 alpha:1.0]];
    self.contratPriceFiled.borderStyle=UITextBorderStyleRoundedRect;
    [self.view  addSubview:self.contratPriceFiled];
    
    
    self.contratTotalLabel = [[UILabel alloc] initWithFrame:CGRectMake(400, 620, 100, 50)];
    [self.contratTotalLabel setText:@"总  价"];    
    self.contratTotalLabel.font = [UIFont systemFontOfSize:22];
    self.contratTotalLabel.textColor=[UIColor colorWithRed:124/255.0 green:124/255.0 blue:124/255.0 alpha:1.0];
    [self.contratTotalLabel setBackgroundColor:[UIColor clearColor]];
    //加载lable
    [self.view  addSubview:self.contratTotalLabel];
	// Do any additional setup after loading the view.
    
    
    self.contratTotalFiled = [[UITextField alloc] initWithFrame:CGRectMake(500, 620, 200, 50)];
    [self.contratTotalFiled setText:[numberFormatter stringFromNumber:[self.contract totalAmount]]];
    [self.contratTotalFiled setDelegate:self];
    [self.contratTotalFiled setBackgroundColor:[UIColor colorWithRed:215/255.0 green:226/255.0 blue:243/255.0 alpha:1.0]];
    self.contratTotalFiled.borderStyle=UITextBorderStyleRoundedRect;
    
    [self.view  addSubview:self.contratTotalFiled];
    /*******价格 end********/
    
    self.contratPayLabel = [[UILabel alloc] initWithFrame:CGRectMake(74, 700, 100, 50)];
    [self.contratPayLabel setText:@"付款方式"];    
    self.contratPayLabel.font = [UIFont systemFontOfSize:22];
    self.contratPayLabel.textColor=[UIColor colorWithRed:124/255.0 green:124/255.0 blue:124/255.0 alpha:1.0];
    [self.contratPayLabel setBackgroundColor:[UIColor clearColor]];
    //加载lable
    [self.view  addSubview:self.contratPayLabel];
   
    
    UILabel* leftLabel = [[UILabel alloc] initWithFrame:CGRectMake(240, 700, 80, 50)];
    [leftLabel setText:@"分期付款"];    
    leftLabel.font = [UIFont systemFontOfSize:20];
    leftLabel.textColor=[UIColor colorWithRed:124/255.0 green:124/255.0 blue:124/255.0 alpha:1.0];
    [leftLabel setBackgroundColor:[UIColor clearColor]];
    //加载lable
    [self.view  addSubview:leftLabel];
    
    
    self.leftSwitch = [[UISwitch alloc] initWithFrame:CGRectMake(330, 705, 50, 50)];
    
    [self.leftSwitch addTarget:self action:@selector(switchLeftAction:) forControlEvents:UIControlEventValueChanged];    
    // in case the parent view draws with a custom color or gradient, use a transparent color
    self.leftSwitch.backgroundColor = [UIColor clearColor];
    
    [self.leftSwitch setAccessibilityLabel:NSLocalizedString(@"StandardSwitch", @"")];
    [self.view addSubview:self.leftSwitch];
    
    UILabel* rightLabel = [[UILabel alloc] initWithFrame:CGRectMake(500, 700, 100, 50)];
    [rightLabel setText:@"全额付款"];    
    rightLabel.font = [UIFont systemFontOfSize:20];
    rightLabel.textColor=[UIColor colorWithRed:124/255.0 green:124/255.0 blue:124/255.0 alpha:1.0];
    [rightLabel setBackgroundColor:[UIColor clearColor]];
    //加载lable
    [self.view  addSubview:rightLabel];
    
    self.rightSwitch = [[UISwitch alloc] initWithFrame:CGRectMake(590, 705, 50, 50)];
    
    [self.rightSwitch addTarget:self action:@selector(switchRightAction:) forControlEvents:UIControlEventValueChanged];
    
    // in case the parent view draws with a custom color or gradient, use a transparent color
    self.rightSwitch.backgroundColor = [UIColor clearColor];
    
    [self.rightSwitch setAccessibilityLabel:NSLocalizedString(@"StandardSwitch", @"")];
    [self.view addSubview:self.rightSwitch];
    
    
    if([[self.contract modePayment] isEqualToString:@"1"] ){
        self.rightSwitch.on = YES;
    }else{
        self.leftSwitch.on = YES;
    }


    UIButton* buyButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [buyButton setFrame:CGRectMake(26, 821, 282, 73)];
    [buyButton setImage:[UIImage imageNamed:@"cancel_button_up.png"] forState:UIControlStateNormal];
    [buyButton setImage:[UIImage imageNamed:@"cancel_button_down.png"] forState:UIControlStateHighlighted];
    backButton.backgroundColor=[UIColor clearColor];
    //[buyButton setTitle:@"取消" forState:UIControlStateNormal]; //设置button的标题
	[buyButton addTarget:self action:@selector(buyButtonPress:) forControlEvents:UIControlEventTouchUpInside]; //定义点击时的响应函数
    
    [self.view addSubview:buyButton];
    
    UIButton* orderButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [orderButton setFrame:CGRectMake(465, 821, 282, 73)];
    [orderButton setBackgroundColor:[UIColor clearColor]];
    [orderButton setImage:[UIImage imageNamed:@"pay_button_up.png"] forState:UIControlStateNormal];
    [orderButton setImage:[UIImage imageNamed:@"pay_button_down.png"] forState:UIControlStateHighlighted];
    //[orderButton setTitle:@"付款" forState:UIControlStateNormal]; //设置button的标题
	[orderButton addTarget:self action:@selector(orderButtonPress:) forControlEvents:UIControlEventTouchUpInside]; //定义点击时的响应函数
    
    [self.view addSubview:orderButton];

}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
-(void) setItems: (smMboSmTbContract*) obj title:(NSString*) tt{
    
    self.title = tt;
    self.contract = obj;
}
-(void) buyButtonPress: (UIButton*) bt {
    [self.navigationController popViewControllerAnimated:YES];
}
-(void) orderButtonPress: (UIButton*) bt {
    smPaymentController* paymentController = [[smPaymentController alloc] init];
    [self.navigationController pushViewController:paymentController animated:YES];
    
    // smloginController* loginController = [[smloginController alloc] init];
    // [self.navigationController pushViewController:loginController animated:YES];
}
- (void)switchLeftAction:(id)sender{
    UISwitch *mySwitch = (UISwitch *)sender;
    BOOL setting = mySwitch.isOn;	//获得开关状态
    if(setting){
        [self.rightSwitch setOn:FALSE];
    }else{
        [self.rightSwitch setOn:YES];

    }
    //[leftSwitch setOn:setting animated:YES];	//设置开关状态
    //[rightSwitch setOn:setting animated:YES];
}
- (void)switchRightAction:(id)sender{
    UISwitch *mySwitch = (UISwitch *)sender;
    BOOL setting = mySwitch.isOn;	//获得开关状态
    //[leftSwitch setOn:setting animated:YES];	//设置开关状态
    //[rightSwitch setOn:setting animated:YES];
    if(setting){
        [self.leftSwitch setOn:FALSE];
    }else{
        [self.leftSwitch setOn:YES];

    }
}
-(void) backClick:(UIButton*) bt{
    
    [self.navigationController popViewControllerAnimated:YES];
}

@end
